package club.laowang.chain.validation;

import club.laowang.chain.execption.ValidatorException;

import java.util.ArrayList;
import java.util.List;

public class ValidatorContext {
    private final List<String> errorMessageList = new ArrayList<>();

    public void appendError(String message) {
        this.errorMessageList.add(message);
    }

    public void throwExceptionIfNecessary() {
        if (errorMessageList.isEmpty()) {
            return;
        }
        throw new ValidatorException(errorMessageList.toString());
    }
}
